/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bsc.war.populate;

import bsc.ejb.entity.*;
import bsc.ejb.entity.ScoreCardDimension;
import bsc.ejb.metadata.Colorimetry;
import bsc.ejb.metadata.Comparation;
import bsc.ejb.metadata.Framework;
import bsc.ejb.metadata.MapDrawing;
import bsc.ejb.metadata.Unit;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import bsc.war.service.ScoreCardUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author Miguel Angel
 */
public class VisionPopulate extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");


        //Se crea un FrameWork
        try {

            createFramework(request, response, delegate);
        } catch (Exception e) {
            e.printStackTrace();
        }


            return new ModelAndView("advancePopulate");
    }

    public static void createFramework(HttpServletRequest request,
            HttpServletResponse response, DelegateBSC delegate) {

        //Create a Framework
        Framework framework = (Framework) Factory.getBean("Framework");
        framework.setName("Municipio de Oaxaca");
        framework.setDescription("Framework de Trabajo");
        framework.setActive(Boolean.TRUE);

        delegate.createFramework(framework);

        //Create a Colorimetries
        //Green
        Colorimetry colorimetryGreen = (Colorimetry) Factory.getBean("Colorimetry");
        colorimetryGreen.setName("Green");
        colorimetryGreen.setPriority(1);
        colorimetryGreen.setFramework(framework);
        colorimetryGreen.setColor("00FF00");
        delegate.createColorimetry(colorimetryGreen);

        //Yellow
        Colorimetry colorimetryYellow = (Colorimetry) Factory.getBean("Colorimetry");
        colorimetryYellow.setName("Yellow");
        colorimetryYellow.setPriority(2);
        colorimetryYellow.setFramework(framework);
        colorimetryYellow.setColor("FFFF00");
        delegate.createColorimetry(colorimetryYellow);

        //Red
        Colorimetry colorimetryRed = (Colorimetry) Factory.getBean("Colorimetry");
        colorimetryRed.setName("Red");
        colorimetryRed.setPriority(3);
        colorimetryRed.setFramework(framework);
        colorimetryRed.setColor("FF0000");
        delegate.createColorimetry(colorimetryRed);

        //Create Comparation
        Comparation comparationReal = (Comparation) Factory.getBean("Comparation");
        comparationReal.setName("Real");
        comparationReal.setType(Comparation.Type.REAL);
        comparationReal.setFramework(framework);

        Comparation comparationGoal = (Comparation) Factory.getBean("Comparation");
        comparationGoal.setName("Meta");
        comparationGoal.setType(Comparation.Type.GOAL);
        comparationGoal.setFramework(framework);

        delegate.createComparation(comparationReal);
        delegate.createComparation(comparationGoal);

        Unit unitPesos = (Unit) Factory.getBean("Unit");
        unitPesos.setName("$");
        unitPesos.setDescription("Pesos");
        unitPesos.setFramework(framework);
        delegate.createUnit(unitPesos);

        Unit unitPorcentaje = (Unit) Factory.getBean("Unit");
        unitPorcentaje.setName("%");
        unitPorcentaje.setDescription("Porcentaje");
        unitPorcentaje.setFramework(framework);
        delegate.createUnit(unitPorcentaje);

        //DIMENSIONES
        //DIMENSION TOTAL
        //Populate a new Dimension
        Dimension dimensionNormal = (Dimension) Factory.getBean("Dimension");
        dimensionNormal.setName("SIN_DIMENSION");
        delegate.createDimension(dimensionNormal);

        //Populate a new Member
        DimensionMember dimensionmember1Normal = (DimensionMember) Factory.getBean("DimensionMember");
        dimensionmember1Normal.setName("TOTAL");
        dimensionmember1Normal.setDimension(dimensionNormal);
        delegate.createDimensionMember(dimensionmember1Normal);

        //Create a Designer
        Person personDesigner = (Person) Factory.getBean("Person");
        personDesigner.setName("Usuario Diseñador");
        personDesigner.setEmail("designer@visionengager.com");
        personDesigner.setUsername("designer");
        personDesigner.setPassword("designer");
        personDesigner.setProfile(Person.Profile.DESIGNER);
        delegate.createPerson(personDesigner);


        Person person = (Person) Factory.getBean("Person");
        person.setName("Usuario Administrador");
        person.setEmail("administrator@visionengager.com");
        person.setUsername("administrator");
        person.setPassword("administrator");
        person.setProfile(Person.Profile.ADMINISTRATOR);
        delegate.createPerson(person);



        //Se crea el dominio designer
        ScoreDomain scoreDomainDesigner = (ScoreDomain) Factory.getBean("ScoreDomain");
        scoreDomainDesigner.setName("Dominio de Administradores");
        delegate.createScoreDomain(scoreDomainDesigner);


    }
}
